package me.wanghongyu.railwayquery.model;

import lombok.Getter;

import java.util.ArrayList;
import java.util.List;


@Getter
public class TrainInfo {
	private final String number;
	private final String start;
	private final String end;
	private final String startTime;
	private final String endTime;
	private final String time;
	private final List<Ticket> ticketList;

	public TrainInfo(String number, String start, String end, String startTime, String endTime, String time) {
		this.number = number;
		this.start = start;
		this.end = end;
		this.startTime = startTime;
		this.endTime = endTime;
		this.time = time;
		this.ticketList = new ArrayList<>();
	}

	public void addTicket(Ticket ticket){
		ticketList.add(ticket);
	}

	/*
	检查是否有该车票
	 */

	public Ticket containTicket(String name){
		for (Ticket ticket : ticketList) {
			if(ticket.getName().equals(name)){
				return ticket;
			}
		}
		return null;
	}


	@Override
	public String toString() {
		return "TrainInfo{" +
				"number='" + number + '\'' +
				", start='" + start + '\'' +
				", end='" + end + '\'' +
				", startTime='" + startTime + '\'' +
				", endTime='" + endTime + '\'' +
				", time='" + time + '\'' +
				", ticketList=" + ticketList +
				'}';
	}
}
